package com.li.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

public class AppReadyEvent {
    @Component
    static class AppNoticeListener implements ApplicationListener<ApplicationReadyEvent> {
        private static final Logger logger = LoggerFactory.getLogger(AppNoticeListener.class);

        @Override
        public void onApplicationEvent(ApplicationReadyEvent noticeEvent) {
            logger.info("监听器获取到ApplicationReadyEvent 事件,睡眠当前线程两秒");
            try {
                Thread.sleep(2000);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            logger.info("属性是{}", noticeEvent.getSource());
        }

    }
}
